package rsj.api.report;

import com.alibaba.fastjson.JSONObject;
import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import common.util.BoxUtil;
import common.util.validator.ParameterConversionCheck;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.report.entity.ExportLogParam;
import rsj.api.report.entity.ReportExportLog;
import rsj.service.report.IMyExportService;

import java.util.List;

/**
 * 我的导出
 *
 * @author yuanqinglong
 * @since 2021/7/28 15:39
 */
@RestController
public class MyExportController {


    @Autowired
    private IMyExportService myExportServiceImpl;

    /**
     * 导出客户报表
     *
     * @param param 参数
     * @return {@link Box}
     */
    @RequestMapping(value = "rsj_report_my_export_list")
    public Box exportTable(Box param) {
        MapNode user = param.getMapNode("$user");
        String operatorId = user.getValue("User_Id");
        ExportLogParam exportLogParam = JSONObject.parseObject(JSONObject.toJSONString(param.getMapNode("data").toMap()), ExportLogParam.class);
        exportLogParam.setUserId(operatorId);
        ParameterConversionCheck.parameterConversionCheckFastFail(exportLogParam);
        List<ReportExportLog> reportExportLogs = myExportServiceImpl.myExportList(exportLogParam);
        int count = myExportServiceImpl.myExportCount(exportLogParam);
        return BoxUtil.successBoxToTableData(param, reportExportLogs, count);
    }
}
